<!DOCTYPE html>
<html >
<head>
    <meta charset="UTF-8">
    <title>行程</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">

    <link rel="stylesheet" href="/sunfc/css/weui.css">
    <link rel="stylesheet" href="/sunfc/css/jquery-weui.css">
    <link rel="stylesheet" href="/sunfc/css/style.css">

    <script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

<style type="text/css">

</style>
</head>
<body class="back1">
    <div class="shineiSF">
        <div class="index-top">
            <div class="index-back" onClick="javascript:history.back(-1);">
                <img src="/sunfc/images/back.png" width="15">
            </div>
            <p class="index-title">行程</p>
        </div>
    </div>

    //eword-终点的名称/ epointx=终点的经度/ epointy=终点的纬度/ sword=起点的名称，默认是“我的位置”/ spointx=起点的经度，默认是当前定位的经度/ spointy=起点的纬度，默认是当前定位的纬度
    <iframe id="tx_map" src="http://apis.map.qq.com/tools/routeplan/eword={$trip_data['end_detail']}&epointx={$trip_data['lonlat_end'][0]}&epointy={$trip_data['lonlat_end'][1]}&sword={$trip_data['begin_detail']}&spointx={$trip_data['lonlat_begin'][0]}&spointy={$trip_data['lonlat_begin'][1]}&zoombutton=0&trafficbutton=0&topbar=0&footdetail=0?referer=myapp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&zoombutton=0" style="border:0;position: absolute;width: 100%;height: 60%;top:0;right:0;overflow: hidden;"></iframe>
    <div style="position: absolute;z-index: 1;width: 100%;height: 60%;top:0;right:0;"></div>

    <div style="position: fixed;bottom:0;right:0;width: 100%;">
    <div class="index-box index-xingchengz">
        <div class="weui-cells">
            <div class="weui-cell left0">
                <div class="weui-cell__hd">
                    <div class="touxiang">
                        <img class="t-photo" src="{$trip_data['headimgurl']}" width="60" height="60">
                        {if  condition="($trip_data['sex']) eq 2"}
                        <img class="t-icon" src="/sunfc/images/sex2.png" width="15">
                        {else /}
                        <img class="t-icon" src="/sunfc/images/sex1.png" width="15">
                        {/if}
                    </div>
                </div>
                <div class="weui-cell__bd pos-tel">
                    <p class="f17">{$trip_data['nickname']}</p>
                    <p class="xcz-chexing"> 
                        <span class="xinren">信任值{$trip_data['trust_rank']}分</span>
                        <span>{$trip_data['car_info']}</span>
                    </p>
                    <div class="pos-tel-abs"><a href="tel:{$trip_data['tel']}"><img src="/sunfc/images/tel.png" width="30"></a></div>
                </div>
            </div>
            <div class="weui-cell left0">

                <div class="weui-cell__bd xingchengz">
                    
                    <div class="weui-cells">
                        <div class="weui-cell">
                            <div class="weui-cell__hd">
                                <img src="/sunfc/images/wait.png" width="8" class="wait">
                            </div>
                            <div class="weui-cell__bd">
                                <p>
                                    <span>{$trip_data['depart_time']}</span>
                                    <span class="font1">{$trip_data['number']}坐</span>
                                    <!--<span class="font2">95%顺路</span>-->
                                </p>
                            </div>
                        </div>
                        <div class="weui-cell">
                            <div class="weui-cell__hd">
                                <span class="dian"></span>
                            </div>
                            <div class="weui-cell__bd">
                                <p>
                                    <span>{$trip_data['begin_place']}</span>
                                    <span class="font1">{$trip_data['begin_detail']}</span>
                                </p>
                            </div>
                        </div>
                        <div class="weui-cell">
                            <div class="weui-cell__hd">
                                <span class="dian2"></span>
                            </div>
                            <div class="weui-cell__bd">
                                <p>
                                    <span>{$trip_data['end_place']}</span>
                                    <span class="font1">{$trip_data['end_detail']}</span>
                                </p>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <div class="weui-cell left0">
                <div class="weui-cell__bd">
                    <p class="xingchengz-tel" id="time">
                        {if condition="$trip_data['type'] eq 2"}
                            {if condition="$trip_data['status'] eq 0"}
                            <a href="javascript:;" onclick="cancle({$trip_data['id']})" class="telephone" style="padding:3px 60px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;float:left;"> 取消</a>
                            {else /}
                                {if condition="$trip_data['status'] eq 2"}
                                <a href="{:url('sunfc.driver/index')}" class="telephone" style="padding:3px 40px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;">已完成</a>
                                {else /}
                                <a href="javascript:;" onclick="down_car({$trip_data['id']})" class="telephone" style="padding:3px 40px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;">确认到达</a>
                                {/if}
                            {/if}
                        {else /}
                            {if condition="$trip_data['status'] eq 0"}
                            <a href="javascript:;" onclick="cancle({$trip_data['id']})" class="telephone" style="padding:3px 60px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;float:left;"> 取消</a>
                            <!--<a href="javascript:;" onclick="up_car({$trip_data['id']})" class="telephone" style="padding:3px 60px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;">上车 </a>-->
                            <a href="javascript:;" onclick="up_car1({$trip_data['id']})" class="telephone" style="padding:3px 60px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;">上车 </a>
                            {else /}
                                {if condition="$trip_data['status'] eq 2"}
                                <a href="{:url('sunfc.passenger/index')}"  class="telephone" style="padding:3px 40px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;">已完成</a>
                                {else /}
                                <a href="javascript:;" onclick="down_car({$trip_data['id']})" class="telephone" style="padding:3px 40px;background: #4b4c5e;color:#fff;border-radius: 3px;font-size: 15px;">下车</a>
                                {/if}
                            {/if}
                        {/if}
                    </p>
                </div>
            </div>
        </div>
    </div>
    </div>

    <script src="/sunfc/js/jquery.min.js"></script>
    <script src="/sunfc/js/jquery-weui.min.js"></script>
    <script>
        $(function () {
            if($("#time a").text()=="已完成"){
                alert("已完成");
                window.location.href="{:url('index')}";
            }else{
                setInterval(function () {
                    $.ajax({
                        type : "POST",
                        url : "{:url('sunfc.passenger/down_car_ok')}",
                        data : {
                            order_id:"{$trip_data['id']}"
                        },
                        success : function(result) {
                            $("#time a").text()=="行程已结束";
                        }
                    });
                },5000);
            }
        })

        function cancle(id){
            $.confirm("您确定取消预约吗?", "取消预约", function() {
                //确定操作
                $.get("{:url('sunfc.passenger/cancel_ordering')}?"+"order_id="+id,function(data){
                    if(data==1){
                        $.toast("取消成功!");
                        window.location.href="{:url('index')}";
                    }
                });
            }, function() {
                //取消操作
            });
        }


        //上车支付
        function up_car1(id){
            //$.toast(id);
            $.confirm("您确定上车吗?", "确认上车?", function() {
                //确定操作
                $.ajax({
                    type:"POST",
                    url:"{:url('sunfc.passenger/up_car1')}",
                    data:{
                        order_id:"{$trip_data['id']}"
                    },
                    async:true,
                    success:function (data) {
                        console.log(data);

                        if(data.code == 1){

                            $.toast("上车成功!");
                            window.location.href="{:url('sunfc.passenger/trip')}?order_id="+id;
                        }else{
                            $.toast("上车失败!");
                        }

                    }
                })
            }, function() {
                //取消操作
            });
        }




        //上车支付
        function up_car(id){
            $.toast(id);
            $.confirm("您确定上车吗?", "确认上车?", function() {
                //确定操作
                $.ajax({
                    type:"GET",
                    url:"{:url('sunfc.passenger/up_car')}",
                    data:{
                        order_id:"{$trip_data['id']}"
                    },
                    dataType:"json",
                    async:true,
                    success:function (data) {

                        if(data.code == 1){

                            callpay(data.data);
                            $.toast("支付成功!");

                        }else{
                            $.toast("支付失败!");
                        }

                      /*  $.toast("支付成功!");
                        $("#time a").text()=="已支付";
                        window.location.href="{:url('sunfc.passenger/trip')}?"+"order_id="+data;*/
                    }
                })
            }, function() {
                //取消操作
            });
        }

        function jsApiCall(jsApiParameters)
        {
            WeixinJSBridge.invoke(
                'getBrandWCPayRequest',
                {jsApiParameters},
                function(res){
                    if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                        //使用以上方式判断前端返回,微信团队郑重提示：
                        // res.err_msg将在用户支付成功后返回
                        //  ok，但并不保证它绝对可靠。
                        //跳转页面window.localtion.href='';
                        window.localtion.href="{:url('order/lists')}";
                    }else{
                        alert('支付出现错误！'+res.err_code+res.err_desc+res.err_msg);
                    }
                }
            );
        }
        function callpay(jsApiParameters)
        {
            if (typeof WeixinJSBridge == "undefined"){
                if( document.addEventListener ){
                    document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
                }else if (document.attachEvent){
                    document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                    document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
                }
            }else{
                jsApiCall(jsApiParameters);
            }
        }

        function down_car(id){
             $.confirm("您确定要下车吗?", "确认下车?", function() {
                 //确定操作
                 $.get("{:url('sunfc.passenger/down_car')}?"+"order_id="+id,function(data){
                     if(data==1){
                         $.toast("下车成功");
                         window.location.href="{:url('index')}";
                     }else{
                         $.toast("下车成功");
                         window.location.href="{:url('index')}";
                     }
                 });
             }, function() {
                 //取消操作
             });
        }
    </script>
</body>
</html>

